/****
 * AOC starter
 * Copyright (c) 2010, 02nz
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * Latest version aviliable through the world-wide-web at the following url:
 * http://code.google.com/p/aoc-starter/
 ****/

#include <windows.h>
#include <commctrl.h>
#include "ui.h"
#include "aoc.h"
#include "_patcher.h"

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")

PCWSTR gConfig = 0;
PCWSTR gPath = 0;
ULONG  gPlaySoundW;

void _cdecl main()
{
	if( CreateMutexA(NULL, FALSE, "AOC_SHIT") != NULL &&
		GetLastError() == ERROR_ALREADY_EXISTS)
	{
		ExitProcess(0);
	//	FatalAppExitA(0, "Already running!");
	}

	WCHAR Tmp[MAX_PATH];
	PWSTR e = &Tmp[ GetModuleFileName(GetModuleHandle(0), Tmp, MAX_PATH) ];

	lstrcpy(e - 3, L"ini");
	gConfig = _lstrdup(Tmp);

	while(e >= Tmp && *e != '\\' && *e != '/')
		--e;
	e[1] = 0;
	gPath = _lstrdup(Tmp);

	HMODULE pWmm = LoadLibraryEx(L"WINMM.DLL", 0, LOAD_IGNORE_CODE_AUTHZ_LEVEL|DONT_RESOLVE_DLL_REFERENCES);
	gPlaySoundW = GPA(pWmm, "PlaySoundW");
	FreeLibrary(pWmm);

	new CUI();
}

